package types

import (
	"sync"

	"github.com/gorilla/websocket"
	"gorm.io/gorm"
)

// Client 表示一个WebSocket客户端连接
type Client struct {
	Conn   *websocket.Conn
	UserId string
	Send   chan []byte
	Hub    *Hub
}

// Hub 管理所有活跃的客户端连接
type Hub struct {
	Clients    map[*Client]bool
	Broadcast  chan []byte
	Register   chan *Client
	Unregister chan *Client
	Mu         sync.RWMutex
	DB         *gorm.DB
}

// WebSocketMessage WebSocket消息结构
type WebSocketMessage struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

// VoucherNotification 优惠券推送消息
type VoucherNotification struct {
	Type      string                 `json:"type"`
	VoucherId string                 `json:"voucher_id"`
	Title     string                 `json:"title"`
	Amount    float64                `json:"amount"`
	Stock     int                    `json:"stock"`
	BeginTime string                 `json:"begin_time"`
	EndTime   string                 `json:"end_time"`
	Message   string                 `json:"message"`
	Data      map[string]interface{} `json:"data,omitempty"`
	Timestamp int64                  `json:"timestamp"`
}

// MessageType WebSocket消息类型常量
const (
	MessageTypeNotify    = "notify"
	MessageTypeError     = "error"
	MessageTypeHeartbeat = "heartbeat"
)
